package com.zhujiekaifa.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

//<context:property-placeholder location="jdbc.properties"/>加载外部的properties文件
@PropertySource("jdbc.properties")
public class DataSourceConfigURation {
    /**
     * 这个类专门负责数据源的相关配置
     * 数据源的配置 DataSource（数据源）
     */

    @Value("${jdbc.driver}")
    private String driver;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean("dataSource")
    public ComboPooledDataSource getDataSource() throws Exception {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass(driver);
        dataSource.setJdbcUrl(url);
        dataSource.setUser(username);
        dataSource.setPassword(password);
        return  dataSource;
    }

}
